package com.hc.dfs.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hc.dfs.activity.R;
import com.hc.dfs.entities.mobile.FollowDetail;

/** 
 * @author 王洪胜  E-mail:  
 * @version 创建时间：2013-2-26 下午1:37:19
 * 
 * 类说明：公文跟踪ListView中交替填充Item
 *
 */
public class FollowAdapter extends BaseAdapter {

	//上下文环境
	private  LayoutInflater mInflater;
	//数据集合
	private List<FollowDetail> dataList;
	
	//构造方法
	public FollowAdapter(Context context, List<FollowDetail> list){
		this.mInflater = LayoutInflater.from(context);
		dataList = list;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	//内容部类ViewHolder存放Item中的view控件
	static class ViewHolder{
		TextView name, content, type, date;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		//如果item view为空则初始化数据
//		if(convertView==null){
			System.out.println("@"+position);
			convertView=mInflater.inflate((position%2==0)?R.layout.follow_item_left:R.layout.follow_item_right,null);
			holder = new ViewHolder();
			holder.name=(TextView) convertView.findViewById(R.id.name);
			holder.content=(TextView) convertView.findViewById(R.id.content);
			holder.type=(TextView) convertView.findViewById(R.id.type);
			holder.date=(TextView) convertView.findViewById(R.id.date);
//			convertView.setTag(holder);
//		}else{
//			holder = (ViewHolder) convertView.getTag();
//		}
		holder.name.setText(dataList.get(position).getName());
		holder.content.setText(dataList.get(position).getContent()+position);
		holder.type.setText(dataList.get(position).getType());
		holder.date.setText(null);
		return convertView;
	}

}
